﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ComunesMGI.DataTypes;
using ClienteWinMGI.Logica;
using ComunesMGI.Mensajes;

namespace ClienteWinMGI.Presentacion
{
    public partial class ModificarCliente : Form
    {
        private DataCliente _dataCliente;
        public ModificarCliente(DataCliente dc)
        {
            InitializeComponent();
            this._dataCliente = dc;
            txtNomCli.Text = _dataCliente.Nombre;
        }

        private void clearValidator()
        {
            imgValidator.Visible = false;
            lblValidator.Visible = false;
        }

        private void showValidator(string textoValidator)
        {
            imgValidator.Visible = true;
            lblValidator.Visible = true;
            lblValidator.Text = textoValidator;
        }

        private void txtNomCli_TextChanged(object sender, EventArgs e)
        {
            clearValidator();
        }

        private void btnModificar_Click(object sender, EventArgs e)
        {
            if (txtNomCli.Text == "")
            {
                showValidator("Debe ingresar el nombre del cliente");

            }
            else 
            {
                try
                {
                    IClientes ic = LogicaFactory.getInstance().getIClientes();
                    DataCliente dataCli = new DataCliente(this._dataCliente.Codigo, txtNomCli.Text);
                    ic.ModificarCliente(dataCli);
                    Notificacion notif = new Notificacion("Modificacion exitosa", "Modificacion exitosa", "Se ha modificado al cliente con exito");
                    notif.ShowDialog();
                    this.Close();
                }
                catch (Exception ex)
                {
                    Error err = new Error("Error", "", ex.Message);
                    err.ShowDialog();
                }
            }
        }

        private void btnCancelarCliente_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void imgValidator_Click(object sender, EventArgs e)
        {

        }

        private void lblValidator_Click(object sender, EventArgs e)
        {

        }
    }
}
